/*================================================================
*   Copyright (C) 2024 baichao All rights reserved.
*
*   文件名称：main.c
*   创 建 者：baichao
*   创建日期：2024年04月07日
*   描    述：
*
================================================================*/

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

struct ListNode {
  int32_t val;
  struct ListNode *next;
};

struct ListNode *reverseList(struct ListNode *head) {
  struct ListNode *nextNode = NULL;
  struct ListNode *after_head = NULL;

  struct ListNode *currNode = head;
  while (currNode != NULL) {
    nextNode = currNode->next;
    currNode->next = after_head;
    after_head = currNode;
    currNode = nextNode;
  }
  return after_head;
}

int main() {
  struct ListNode *currNode = NULL;
  struct ListNode *listA = (struct ListNode *)malloc(sizeof(struct ListNode));

  listA->val = 1;
  listA->next = (struct ListNode *)malloc(sizeof(struct ListNode));
  currNode = listA->next;

  currNode->val = 2;
  currNode->next = (struct ListNode *)malloc(sizeof(struct ListNode));
  currNode = currNode->next;

  currNode->val = 3;
  currNode->next = (struct ListNode *)malloc(sizeof(struct ListNode));
  currNode = currNode->next;

  currNode->val = 4;
  currNode->next = (struct ListNode *)malloc(sizeof(struct ListNode));
  currNode = currNode->next;

  currNode->val = 5;
  currNode->next = NULL;

  struct ListNode *afterList = reverseList(listA);

  return 0;
}
